{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Confirmed coronavirus cases by selected countries"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "ENV[\"GRDISPLAY\"] = \"js\"\n",
    "using GR\n",
    "\n",
    "using CSV"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "countries = [\"Germany\", \"China\", \"Italy\", \"France\", \"Spain\", \"US\"];"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Grab data from the Johns Hopkins University Center for Systems Science and Engineering (JHU CSSE)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "url = \"https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv\";"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "download(url, \"covid-19.csv\");"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = convert(Matrix, CSV.read(\"covid-19.csv\"))\n",
    "ncountries, ncols = size(data)\n",
    "ndays = ncols - 4;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "cummulated = Dict()\n",
    "for i in 1:ncountries\n",
    "    country = data[i, 2]\n",
    "    if country in countries\n",
    "        if !haskey(cummulated, country) cummulated[country] = zeros(ndays) end\n",
    "        cummulated[country] .+= data[i, 5:end]\n",
    "    end\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "day = collect(Float64, 1:ndays);\n",
    "confirmed = hcat([cummulated[country] for country in countries]...);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plot(day, confirmed, xlim=(0, ndays+1), ylim=(10, 5000000), ylog=true,\n",
    "     title=\"Confirmed SARS–CoV–2 infections\", xlabel=\"Day\", ylabel=\"Confirmed\",\n",
    "     labels=countries, location=4)"
   ]
  }
 ],
 "metadata": {
  "@webio": {
   "lastCommId": null,
   "lastKernelId": null
  },
  "kernelspec": {
   "display_name": "Julia 1.4.2",
   "language": "julia",
   "name": "julia-1.4"
  },
  "language_info": {
   "file_extension": ".jl",
   "mimetype": "application/julia",
   "name": "julia",
   "version": "1.4.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
